{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ef7edf4d",
   "metadata": {},
   "source": [
    "* 2023-10-23\n",
    "* 课程： Python语言\n",
    "* week07"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d26f3a4b",
   "metadata": {},
   "source": [
    "# 1.体验列表"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "980e9fdc",
   "metadata": {},
   "source": [
    "* 思考：如果把我们班同学的名字都存起来，你会怎么做？用变量name1、name2、name3...来存么？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d0e65dbc",
   "metadata": {},
   "outputs": [],
   "source": [
    "name1 = \"张三\"\n",
    "name2 = \"李华\"\n",
    "name3 = \"王玮\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "9fcdd36f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'张三'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "661a683a",
   "metadata": {},
   "outputs": [],
   "source": [
    "name = \"张三，李华，王玮\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "bd2472b5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'张三，李华，王玮'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "200ce55f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'张三'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name[:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "faaefa97",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'李华'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name[3:5]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c4f4befc",
   "metadata": {},
   "source": [
    "* 综上，一种新的数据结构就此而生"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "6d171e68",
   "metadata": {},
   "outputs": [],
   "source": [
    "name_list = [\"张三\",\"李华\",\"王玮\",\"李小明\"]\n",
    "# 可以存放字符串和数字\n",
    "# 1.保持数据插入的顺序 “有序性”"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "b4302837",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['张三', '李华', '王玮', '李小明']"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "14b37721",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'张三'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "264af8a2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'李华'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_list[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "ceb9a3f4",
   "metadata": {},
   "outputs": [],
   "source": [
    "name_学号 = [2210130078,2210130079,2210130080]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "ad4753eb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2210130078, 2210130079, 2210130080]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_学号"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "c3c59d3e",
   "metadata": {},
   "outputs": [],
   "source": [
    "name_list[1] = \"李树人\"\n",
    "# 2.列表是可变的，我们可以修改条目 “可变性”，字符串和数值不可变。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "f69eeb01",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['张三', '李树人', '王玮', '李小明']"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "af022129",
   "metadata": {},
   "outputs": [],
   "source": [
    "name_张三 = [\"张三\",2210130079,19,180,75,\"jack\",[\"python\",\"移动互联网\",\"UI设计\"]]\n",
    "# 同一个列表可以包括字符串和数字、列表 \"数据的异构性\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "e7e5f8f5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['张三', 2210130079, 19, 180, 75, 'jack', ['python', '移动互联网', 'UI设计']]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_张三"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "64c9423d",
   "metadata": {},
   "source": [
    "* 虽然列表可以存放不同类型的数据，但是一般情况我们存放的数据都是同一种数据类型的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "a1cae9dd",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 允许重复的数据 “数据的重复性”\n",
    "网三_python成绩 = [95,97,94,94,95,97]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "d3391de7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[95, 97, 94, 94, 95, 97]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_python成绩"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "31a84bfc",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "9f1f1d37",
   "metadata": {},
   "source": [
    "## 1.2 创建列表\n",
    "> 1.使用list()创建列表\n",
    "\n",
    "> 2.直接使用[]创建列表，中间的元素用英文的逗号隔开\n",
    "\n",
    "> 3.创建一个空列表，方法也是上面两种"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "4fd1880f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[18, 19, 18, 20]\n",
      "<class 'list'>\n"
     ]
    }
   ],
   "source": [
    "# 1.使用list()创建列表\n",
    "my_list1 = list((18,19,18,20))\n",
    "print(my_list1)\n",
    "print(type(my_list1))\n",
    "# list是列表的意思"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "bc22b4aa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[75, 80, 74, 75]\n",
      "<class 'list'>\n"
     ]
    }
   ],
   "source": [
    "# 2.直接使用[]创建列表，中间的元素用英文的逗号隔开\n",
    "my_list2 = [75,80,74,75]\n",
    "print(my_list2)\n",
    "print(type(my_list2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "1c4df693",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['python']"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_list3 = [\"python\"]\n",
    "my_list3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "ce4ea258",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '~']\n"
     ]
    }
   ],
   "source": [
    "my_list4 = list(\"hello world~\")\n",
    "print(my_list4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "2d49ccf9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[]\n",
      "<class 'list'>\n"
     ]
    }
   ],
   "source": [
    "# 3.创建空列表\n",
    "empty_list = []\n",
    "print(empty_list)\n",
    "print(type(empty_list))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7f83203a",
   "metadata": {},
   "source": [
    "## 1.3查看列表的长度 : len()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "0ff5ddc7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(my_list4)\n",
    "#包括空格和标点符号"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "19a347f5",
   "metadata": {},
   "source": [
    "## 1.4 列表的取值和切片\n",
    "* index：取值\n",
    "* slice：切片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "7a43dfc6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['p', 'y', 't', 'h', 'o', 'n']\n"
     ]
    }
   ],
   "source": [
    "python_list = list(\"python\")\n",
    "print(python_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "dfc9be2a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'p'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "python_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "7cbcf047",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'n'"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "python_list[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "134536dc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['o', 'n']"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "python_list[4:]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "53fd5a90",
   "metadata": {},
   "source": [
    "## 1.5列表的一般方法\n",
    "* 笔记：数据如何处理数据诞生之后非常重要的事情\n",
    "* 数据的基本操作流程：\n",
    "\n",
    "> 1.增加 Add\n",
    "\n",
    "> 2.减少/删除 remove\n",
    "\n",
    "> 3.查询 find\n",
    "\n",
    "> 4.修改 update"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e21e3aff",
   "metadata": {},
   "source": [
    "### 增加\n",
    "help(name_list.append)\n",
    "* object 理解为对象\n",
    "* append增加到末尾的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "7129cdc2",
   "metadata": {},
   "outputs": [],
   "source": [
    "name_list.append(\"李树人\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "e6b6f1fa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['张三', '李树人', '王玮', '李小明', '李树人']"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "d52694cb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function insert:\n",
      "\n",
      "insert(index, object, /) method of builtins.list instance\n",
      "    Insert object before index.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(name_list.insert)\n",
    "# before index ，在取值的前面"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "6cce214a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on class str in module builtins:\n",
      "\n",
      "class str(object)\n",
      " |  str(object='') -> str\n",
      " |  str(bytes_or_buffer[, encoding[, errors]]) -> str\n",
      " |  \n",
      " |  Create a new string object from the given object. If encoding or\n",
      " |  errors is specified, then the object must expose a data buffer\n",
      " |  that will be decoded using the given encoding and error handler.\n",
      " |  Otherwise, returns the result of object.__str__() (if defined)\n",
      " |  or repr(object).\n",
      " |  encoding defaults to sys.getdefaultencoding().\n",
      " |  errors defaults to 'strict'.\n",
      " |  \n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __add__(self, value, /)\n",
      " |      Return self+value.\n",
      " |  \n",
      " |  __contains__(self, key, /)\n",
      " |      Return key in self.\n",
      " |  \n",
      " |  __eq__(self, value, /)\n",
      " |      Return self==value.\n",
      " |  \n",
      " |  __format__(self, format_spec, /)\n",
      " |      Return a formatted version of the string as described by format_spec.\n",
      " |  \n",
      " |  __ge__(self, value, /)\n",
      " |      Return self>=value.\n",
      " |  \n",
      " |  __getattribute__(self, name, /)\n",
      " |      Return getattr(self, name).\n",
      " |  \n",
      " |  __getitem__(self, key, /)\n",
      " |      Return self[key].\n",
      " |  \n",
      " |  __getnewargs__(...)\n",
      " |  \n",
      " |  __gt__(self, value, /)\n",
      " |      Return self>value.\n",
      " |  \n",
      " |  __hash__(self, /)\n",
      " |      Return hash(self).\n",
      " |  \n",
      " |  __iter__(self, /)\n",
      " |      Implement iter(self).\n",
      " |  \n",
      " |  __le__(self, value, /)\n",
      " |      Return self<=value.\n",
      " |  \n",
      " |  __len__(self, /)\n",
      " |      Return len(self).\n",
      " |  \n",
      " |  __lt__(self, value, /)\n",
      " |      Return self<value.\n",
      " |  \n",
      " |  __mod__(self, value, /)\n",
      " |      Return self%value.\n",
      " |  \n",
      " |  __mul__(self, value, /)\n",
      " |      Return self*value.\n",
      " |  \n",
      " |  __ne__(self, value, /)\n",
      " |      Return self!=value.\n",
      " |  \n",
      " |  __repr__(self, /)\n",
      " |      Return repr(self).\n",
      " |  \n",
      " |  __rmod__(self, value, /)\n",
      " |      Return value%self.\n",
      " |  \n",
      " |  __rmul__(self, value, /)\n",
      " |      Return value*self.\n",
      " |  \n",
      " |  __sizeof__(self, /)\n",
      " |      Return the size of the string in memory, in bytes.\n",
      " |  \n",
      " |  __str__(self, /)\n",
      " |      Return str(self).\n",
      " |  \n",
      " |  capitalize(self, /)\n",
      " |      Return a capitalized version of the string.\n",
      " |      \n",
      " |      More specifically, make the first character have upper case and the rest lower\n",
      " |      case.\n",
      " |  \n",
      " |  casefold(self, /)\n",
      " |      Return a version of the string suitable for caseless comparisons.\n",
      " |  \n",
      " |  center(self, width, fillchar=' ', /)\n",
      " |      Return a centered string of length width.\n",
      " |      \n",
      " |      Padding is done using the specified fill character (default is a space).\n",
      " |  \n",
      " |  count(...)\n",
      " |      S.count(sub[, start[, end]]) -> int\n",
      " |      \n",
      " |      Return the number of non-overlapping occurrences of substring sub in\n",
      " |      string S[start:end].  Optional arguments start and end are\n",
      " |      interpreted as in slice notation.\n",
      " |  \n",
      " |  encode(self, /, encoding='utf-8', errors='strict')\n",
      " |      Encode the string using the codec registered for encoding.\n",
      " |      \n",
      " |      encoding\n",
      " |        The encoding in which to encode the string.\n",
      " |      errors\n",
      " |        The error handling scheme to use for encoding errors.\n",
      " |        The default is 'strict' meaning that encoding errors raise a\n",
      " |        UnicodeEncodeError.  Other possible values are 'ignore', 'replace' and\n",
      " |        'xmlcharrefreplace' as well as any other name registered with\n",
      " |        codecs.register_error that can handle UnicodeEncodeErrors.\n",
      " |  \n",
      " |  endswith(...)\n",
      " |      S.endswith(suffix[, start[, end]]) -> bool\n",
      " |      \n",
      " |      Return True if S ends with the specified suffix, False otherwise.\n",
      " |      With optional start, test S beginning at that position.\n",
      " |      With optional end, stop comparing S at that position.\n",
      " |      suffix can also be a tuple of strings to try.\n",
      " |  \n",
      " |  expandtabs(self, /, tabsize=8)\n",
      " |      Return a copy where all tab characters are expanded using spaces.\n",
      " |      \n",
      " |      If tabsize is not given, a tab size of 8 characters is assumed.\n",
      " |  \n",
      " |  find(...)\n",
      " |      S.find(sub[, start[, end]]) -> int\n",
      " |      \n",
      " |      Return the lowest index in S where substring sub is found,\n",
      " |      such that sub is contained within S[start:end].  Optional\n",
      " |      arguments start and end are interpreted as in slice notation.\n",
      " |      \n",
      " |      Return -1 on failure.\n",
      " |  \n",
      " |  format(...)\n",
      " |      S.format(*args, **kwargs) -> str\n",
      " |      \n",
      " |      Return a formatted version of S, using substitutions from args and kwargs.\n",
      " |      The substitutions are identified by braces ('{' and '}').\n",
      " |  \n",
      " |  format_map(...)\n",
      " |      S.format_map(mapping) -> str\n",
      " |      \n",
      " |      Return a formatted version of S, using substitutions from mapping.\n",
      " |      The substitutions are identified by braces ('{' and '}').\n",
      " |  \n",
      " |  index(...)\n",
      " |      S.index(sub[, start[, end]]) -> int\n",
      " |      \n",
      " |      Return the lowest index in S where substring sub is found,\n",
      " |      such that sub is contained within S[start:end].  Optional\n",
      " |      arguments start and end are interpreted as in slice notation.\n",
      " |      \n",
      " |      Raises ValueError when the substring is not found.\n",
      " |  \n",
      " |  isalnum(self, /)\n",
      " |      Return True if the string is an alpha-numeric string, False otherwise.\n",
      " |      \n",
      " |      A string is alpha-numeric if all characters in the string are alpha-numeric and\n",
      " |      there is at least one character in the string.\n",
      " |  \n",
      " |  isalpha(self, /)\n",
      " |      Return True if the string is an alphabetic string, False otherwise.\n",
      " |      \n",
      " |      A string is alphabetic if all characters in the string are alphabetic and there\n",
      " |      is at least one character in the string.\n",
      " |  \n",
      " |  isascii(self, /)\n",
      " |      Return True if all characters in the string are ASCII, False otherwise.\n",
      " |      \n",
      " |      ASCII characters have code points in the range U+0000-U+007F.\n",
      " |      Empty string is ASCII too.\n",
      " |  \n",
      " |  isdecimal(self, /)\n",
      " |      Return True if the string is a decimal string, False otherwise.\n",
      " |      \n",
      " |      A string is a decimal string if all characters in the string are decimal and\n",
      " |      there is at least one character in the string.\n",
      " |  \n",
      " |  isdigit(self, /)\n",
      " |      Return True if the string is a digit string, False otherwise.\n",
      " |      \n",
      " |      A string is a digit string if all characters in the string are digits and there\n",
      " |      is at least one character in the string.\n",
      " |  \n",
      " |  isidentifier(self, /)\n",
      " |      Return True if the string is a valid Python identifier, False otherwise.\n",
      " |      \n",
      " |      Call keyword.iskeyword(s) to test whether string s is a reserved identifier,\n",
      " |      such as \"def\" or \"class\".\n",
      " |  \n",
      " |  islower(self, /)\n",
      " |      Return True if the string is a lowercase string, False otherwise.\n",
      " |      \n",
      " |      A string is lowercase if all cased characters in the string are lowercase and\n",
      " |      there is at least one cased character in the string.\n",
      " |  \n",
      " |  isnumeric(self, /)\n",
      " |      Return True if the string is a numeric string, False otherwise.\n",
      " |      \n",
      " |      A string is numeric if all characters in the string are numeric and there is at\n",
      " |      least one character in the string.\n",
      " |  \n",
      " |  isprintable(self, /)\n",
      " |      Return True if the string is printable, False otherwise.\n",
      " |      \n",
      " |      A string is printable if all of its characters are considered printable in\n",
      " |      repr() or if it is empty.\n",
      " |  \n",
      " |  isspace(self, /)\n",
      " |      Return True if the string is a whitespace string, False otherwise.\n",
      " |      \n",
      " |      A string is whitespace if all characters in the string are whitespace and there\n",
      " |      is at least one character in the string.\n",
      " |  \n",
      " |  istitle(self, /)\n",
      " |      Return True if the string is a title-cased string, False otherwise.\n",
      " |      \n",
      " |      In a title-cased string, upper- and title-case characters may only\n",
      " |      follow uncased characters and lowercase characters only cased ones.\n",
      " |  \n",
      " |  isupper(self, /)\n",
      " |      Return True if the string is an uppercase string, False otherwise.\n",
      " |      \n",
      " |      A string is uppercase if all cased characters in the string are uppercase and\n",
      " |      there is at least one cased character in the string.\n",
      " |  \n",
      " |  join(self, iterable, /)\n",
      " |      Concatenate any number of strings.\n",
      " |      \n",
      " |      The string whose method is called is inserted in between each given string.\n",
      " |      The result is returned as a new string.\n",
      " |      \n",
      " |      Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'\n",
      " |  \n",
      " |  ljust(self, width, fillchar=' ', /)\n",
      " |      Return a left-justified string of length width.\n",
      " |      \n",
      " |      Padding is done using the specified fill character (default is a space).\n",
      " |  \n",
      " |  lower(self, /)\n",
      " |      Return a copy of the string converted to lowercase.\n",
      " |  \n",
      " |  lstrip(self, chars=None, /)\n",
      " |      Return a copy of the string with leading whitespace removed.\n",
      " |      \n",
      " |      If chars is given and not None, remove characters in chars instead.\n",
      " |  \n",
      " |  partition(self, sep, /)\n",
      " |      Partition the string into three parts using the given separator.\n",
      " |      \n",
      " |      This will search for the separator in the string.  If the separator is found,\n",
      " |      returns a 3-tuple containing the part before the separator, the separator\n",
      " |      itself, and the part after it.\n",
      " |      \n",
      " |      If the separator is not found, returns a 3-tuple containing the original string\n",
      " |      and two empty strings.\n",
      " |  \n",
      " |  removeprefix(self, prefix, /)\n",
      " |      Return a str with the given prefix string removed if present.\n",
      " |      \n",
      " |      If the string starts with the prefix string, return string[len(prefix):].\n",
      " |      Otherwise, return a copy of the original string.\n",
      " |  \n",
      " |  removesuffix(self, suffix, /)\n",
      " |      Return a str with the given suffix string removed if present.\n",
      " |      \n",
      " |      If the string ends with the suffix string and that suffix is not empty,\n",
      " |      return string[:-len(suffix)]. Otherwise, return a copy of the original\n",
      " |      string.\n",
      " |  \n",
      " |  replace(self, old, new, count=-1, /)\n",
      " |      Return a copy with all occurrences of substring old replaced by new.\n",
      " |      \n",
      " |        count\n",
      " |          Maximum number of occurrences to replace.\n",
      " |          -1 (the default value) means replace all occurrences.\n",
      " |      \n",
      " |      If the optional argument count is given, only the first count occurrences are\n",
      " |      replaced.\n",
      " |  \n",
      " |  rfind(...)\n",
      " |      S.rfind(sub[, start[, end]]) -> int\n",
      " |      \n",
      " |      Return the highest index in S where substring sub is found,\n",
      " |      such that sub is contained within S[start:end].  Optional\n",
      " |      arguments start and end are interpreted as in slice notation.\n",
      " |      \n",
      " |      Return -1 on failure.\n",
      " |  \n",
      " |  rindex(...)\n",
      " |      S.rindex(sub[, start[, end]]) -> int\n",
      " |      \n",
      " |      Return the highest index in S where substring sub is found,\n",
      " |      such that sub is contained within S[start:end].  Optional\n",
      " |      arguments start and end are interpreted as in slice notation.\n",
      " |      \n",
      " |      Raises ValueError when the substring is not found.\n",
      " |  \n",
      " |  rjust(self, width, fillchar=' ', /)\n",
      " |      Return a right-justified string of length width.\n",
      " |      \n",
      " |      Padding is done using the specified fill character (default is a space).\n",
      " |  \n",
      " |  rpartition(self, sep, /)\n",
      " |      Partition the string into three parts using the given separator.\n",
      " |      \n",
      " |      This will search for the separator in the string, starting at the end. If\n",
      " |      the separator is found, returns a 3-tuple containing the part before the\n",
      " |      separator, the separator itself, and the part after it.\n",
      " |      \n",
      " |      If the separator is not found, returns a 3-tuple containing two empty strings\n",
      " |      and the original string.\n",
      " |  \n",
      " |  rsplit(self, /, sep=None, maxsplit=-1)\n",
      " |      Return a list of the substrings in the string, using sep as the separator string.\n",
      " |      \n",
      " |        sep\n",
      " |          The separator used to split the string.\n",
      " |      \n",
      " |          When set to None (the default value), will split on any whitespace\n",
      " |          character (including \\\\n \\\\r \\\\t \\\\f and spaces) and will discard\n",
      " |          empty strings from the result.\n",
      " |        maxsplit\n",
      " |          Maximum number of splits (starting from the left).\n",
      " |          -1 (the default value) means no limit.\n",
      " |      \n",
      " |      Splitting starts at the end of the string and works to the front.\n",
      " |  \n",
      " |  rstrip(self, chars=None, /)\n",
      " |      Return a copy of the string with trailing whitespace removed.\n",
      " |      \n",
      " |      If chars is given and not None, remove characters in chars instead.\n",
      " |  \n",
      " |  split(self, /, sep=None, maxsplit=-1)\n",
      " |      Return a list of the substrings in the string, using sep as the separator string.\n",
      " |      \n",
      " |        sep\n",
      " |          The separator used to split the string.\n",
      " |      \n",
      " |          When set to None (the default value), will split on any whitespace\n",
      " |          character (including \\\\n \\\\r \\\\t \\\\f and spaces) and will discard\n",
      " |          empty strings from the result.\n",
      " |        maxsplit\n",
      " |          Maximum number of splits (starting from the left).\n",
      " |          -1 (the default value) means no limit.\n",
      " |      \n",
      " |      Note, str.split() is mainly useful for data that has been intentionally\n",
      " |      delimited.  With natural text that includes punctuation, consider using\n",
      " |      the regular expression module.\n",
      " |  \n",
      " |  splitlines(self, /, keepends=False)\n",
      " |      Return a list of the lines in the string, breaking at line boundaries.\n",
      " |      \n",
      " |      Line breaks are not included in the resulting list unless keepends is given and\n",
      " |      true.\n",
      " |  \n",
      " |  startswith(...)\n",
      " |      S.startswith(prefix[, start[, end]]) -> bool\n",
      " |      \n",
      " |      Return True if S starts with the specified prefix, False otherwise.\n",
      " |      With optional start, test S beginning at that position.\n",
      " |      With optional end, stop comparing S at that position.\n",
      " |      prefix can also be a tuple of strings to try.\n",
      " |  \n",
      " |  strip(self, chars=None, /)\n",
      " |      Return a copy of the string with leading and trailing whitespace removed.\n",
      " |      \n",
      " |      If chars is given and not None, remove characters in chars instead.\n",
      " |  \n",
      " |  swapcase(self, /)\n",
      " |      Convert uppercase characters to lowercase and lowercase characters to uppercase.\n",
      " |  \n",
      " |  title(self, /)\n",
      " |      Return a version of the string where each word is titlecased.\n",
      " |      \n",
      " |      More specifically, words start with uppercased characters and all remaining\n",
      " |      cased characters have lower case.\n",
      " |  \n",
      " |  translate(self, table, /)\n",
      " |      Replace each character in the string using the given translation table.\n",
      " |      \n",
      " |        table\n",
      " |          Translation table, which must be a mapping of Unicode ordinals to\n",
      " |          Unicode ordinals, strings, or None.\n",
      " |      \n",
      " |      The table must implement lookup/indexing via __getitem__, for instance a\n",
      " |      dictionary or list.  If this operation raises LookupError, the character is\n",
      " |      left untouched.  Characters mapped to None are deleted.\n",
      " |  \n",
      " |  upper(self, /)\n",
      " |      Return a copy of the string converted to uppercase.\n",
      " |  \n",
      " |  zfill(self, width, /)\n",
      " |      Pad a numeric string with zeros on the left, to fill a field of the given width.\n",
      " |      \n",
      " |      The string is never truncated.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Static methods defined here:\n",
      " |  \n",
      " |  __new__(*args, **kwargs) from builtins.type\n",
      " |      Create and return a new object.  See help(type) for accurate signature.\n",
      " |  \n",
      " |  maketrans(...)\n",
      " |      Return a translation table usable for str.translate().\n",
      " |      \n",
      " |      If there is only one argument, it must be a dictionary mapping Unicode\n",
      " |      ordinals (integers) or characters to Unicode ordinals, strings or None.\n",
      " |      Character keys will be then converted to ordinals.\n",
      " |      If there are two arguments, they must be strings of equal length, and\n",
      " |      in the resulting dictionary, each character in x will be mapped to the\n",
      " |      character at the same position in y. If there is a third argument, it\n",
      " |      must be a string, whose characters will be mapped to None in the result.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(str)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "cc2b1187",
   "metadata": {},
   "outputs": [],
   "source": [
    "name_list.insert(2,\"marry\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "dbfd39f8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['张三', '李树人', 'marry', '王玮', '李小明', '李树人']"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "43a300f3",
   "metadata": {},
   "source": [
    "### 2.删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "089d0bc7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function pop:\n",
      "\n",
      "pop(index=-1, /) method of builtins.list instance\n",
      "    Remove and return item at index (default last).\n",
      "    \n",
      "    Raises IndexError if list is empty or index is out of range.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(name_list.pop)\n",
    "# 删除最后一个元素\n",
    "# index=-1 默认的参数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c92515ad",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 不可以删除空的和不在范围的值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "d75c4bb0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'李小明'"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_list.pop()\n",
    "# 删除的时候会先打印出来删除的结果,可指定也可以默认删除最后一位。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "2bfe022d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['李树人', 'marry', 'marry', '王玮']"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "26e7650d",
   "metadata": {},
   "source": [
    "* pop()的第二种使用方法：指定某一位(index)删除\n",
    "* 理论上： 只要让我知道你的位置，我就可以pop（）掉你\n",
    "> 1.只要满足某种条件的位置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "b4fe060c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'李树人'"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_list.pop(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 235,
   "id": "d0e3293b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['张三', 'marry', '王玮', '李小明']"
      ]
     },
     "execution_count": 235,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 237,
   "id": "29fa8f45",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function remove:\n",
      "\n",
      "remove(value, /) method of builtins.list instance\n",
      "    Remove first occurrence of value.\n",
      "    \n",
      "    Raises ValueError if the value is not present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(name_list.remove)\n",
    "# 直接删除那个值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 239,
   "id": "887f0f5d",
   "metadata": {},
   "outputs": [],
   "source": [
    "name_list.remove(\"张三\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "47e8a521",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['张三', 'marry', '王玮', '李小明']\n"
     ]
    }
   ],
   "source": [
    "print(name_list)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "84ab66ce",
   "metadata": {},
   "source": [
    "* 思考：我怎么知道张三在数据列表里面呢？"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8f693ee9",
   "metadata": {},
   "source": [
    "#### 课后作业：把列表的所有方法尝试学习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "6c6342f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 要remote的话，要先查询那个值在不在列表里面。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "631305dd",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
